package appli;

import index.DeserializationMain;
import index.IndexTrie;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import tools.FrenchStemmer;
import tools.FrenchTokenizer;
import tools.Normalizer;
import calculateModel.Modele;
import calculateModel.ModeleBooleanEtendu;
import calculateModel.ModeleVecteur;

public class Application {

	// dossier a analyser

	//public static final String dossier = "../corpus/";
	public static final String dossierTokenizer = "E:/Study/Projet/Annee_3/corpus/texte/";
	public static final String dossierStemmer = "E:/Study/Projet/Annee_3/corpus/texte/";
	//public static final String dossierTokenizer = "lemonde/";
	//public static final String dossierStemmer = "lemonde/";
	public static final String stopWordsFile = "FrenchStopWords.txt";
	private static String dossier;
	private Interface gui;
	private String requete;
	private Modele modele;
	private String typeIndex;
	private boolean remove;
	private HashMap<String, Float> result;

	public Application() {
		gui = new Interface(this);
		requete = null;
	}

	public static void main(String[] args) {

		ArrayList<String> result = new ArrayList<String>();
		Application app = new Application();

	}

	/**
	 * Construire l'index selon le type choisi
	 * 
	 * @param ind
	 *            type d'index
	 */
	public void construireIndex(String ind, String mod, boolean removeEmptyWords) {
		//Normalizer norm = null;
		this.typeIndex = ind;
		this.remove = removeEmptyWords;
		IndexTrie index = null;
		// tokenizer
		if (ind == "Normal") {
			dossier = dossierTokenizer;
			if (removeEmptyWords == true) {
					index = DeserializationMain.getITokenizerStop();
			} else {
				index = DeserializationMain.getITokenizerNoStop();
			}
		}
		// stemmer
		else {
			dossier = dossierStemmer;
			if (removeEmptyWords == true) {
				index = DeserializationMain.getIStemmerStop();
			} else {
				index = DeserializationMain.getIStemmerNoStop();
			}

		}

		System.out.println(new File(dossier).getAbsolutePath());

		//index = new IndexTrie(dossier, norm, removeEmptyWords);

		if (mod == "Vector Model") {
			this.modele = new ModeleVecteur();
		} else {
			this.modele = new ModeleBooleanEtendu(index);
		}

		modele.setIndex(index);
		System.out.println("Type of Index: " + ind);
		System.out.println("Type of Model: " + mod);
		System.out.println("Index construction complete...");
	}

	public static String getDossier() {
		return dossier;
	}

	/**
	 * Calculer la similarite entre la requete et les documents
	 */
	public void searchInfo() {
		modele.setRequete(requete);
		// modele.calculSimularity(20);
		modele.relevanceFeedBack(20, 10);
		this.result = modele.getResult();

	}

	public Modele getModele() {
		return modele;
	}

	public void setModele(Modele modele) {
		this.modele = modele;
	}

	public String getRequete() {
		return requete;
	}

	public void setRequete(String requete) {
		this.requete = requete;
	}

	public HashMap<String, Float> getResult() {
		return result;
	}

	public void setResult(HashMap<String, Float> result) {
		this.result = result;
	}
}
